// pages/wrongList/wrongList.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    date:"日期",
    index:0,   //projectId
    index2:0,  //projectSelectId
    projectArray:["数学","政治","专业课"],
    wrongList:[],
    projectSelect:[]
  },

  navigator:function(e){
    var _this = this
    var date = e.target.dataset.date;
    wx.setStorage({
      key:"data",
      data:["1",parseInt(_this.data.index)+1,parseInt(_this.data.index2)+1,date]
    })
    wx.navigateTo({
      url: '/pages/exam/exam',
    })
  },

  changeDate:function(e){
    var date = e.detail.value
    this.setData({
      date:date
    })
    this.getWrongList()
  },

  changeProject:function(e){
    var project = e.detail.value
    this.getProjectSelect(parseInt(project)+1)
    this.setData({
      index:project,
      index2:0
    })
    this.getWrongList()
  },

  changeProjectSelect:function(e){
    var projectSelectId = parseInt(e.detail.value)+1
    this.setData({
      projectSelectId:projectSelectId,
      index2:e.detail.value
    })
    this.getWrongList()
  },

  getWrongList:function(){
    var _this = this
    var projectId = parseInt(this.data.index)+1
    var projectSelectId = parseInt(this.data.index2)+1
    if(this.data.date=="日期"){
      wx.request({
        url: 'http://localhost:8081/exam/getWrongListById',
        data:{projectId: projectId,projectSelectId:projectSelectId},
        method:"get",
        success:function(res){
          console.log(res.data);
          _this.setData({
            wrongList:res.data.data
          })
        }
      })
    }else{
      var projectSelectId = parseInt(this.data.index2)+1
      wx.request({
        url: 'http://localhost:8081/exam/getWrongListByIdDate',
        data:{projectId: projectId,date:_this.data.date,projectSelectId:projectSelectId},
        method:"get",
        success:function(res){
          console.log(res.data);
          _this.setData({
            wrongList:res.data.data
          })
        }
      })
    }


  },




  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {
    var projectId = parseInt(this.data.index)+1
    this.getProjectSelect(projectId)
    this.getWrongList();

  },

  getProjectSelect:function(projectId){
    var _this = this
    wx.request({
      url: 'http://localhost:8081/exam/getProjectSelect',
      data:{projectId:projectId},
      method:"get",
      success:function(res){
        _this.setData({
          projectSelect:res.data.data
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})